package com.wp.controller;

import com.wp.domain.Account;
import com.wp.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 卫鹏
 * @Description 账户控制器
 * @createTime 2021年10月19日 16:31:00
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/findAll")
    public String findAll(Model model) {
        System.out.println("---表现层：查询所有账户---");
        //调用service的findAll方法:
        List<Account> accounts = accountService.findAll();
        for (Account account : accounts) {
            System.out.println(account);
        }
        //存储到request域中:
        model.addAttribute("accountList", accounts);
        return "list";
    }

    @RequestMapping("/saveAccount")
    public String saveAccount(Account account) {
        System.out.println(account);
        //调用service的saveAccount方法:
        accountService.saveAccount(account);
        //转发：
        return "forward:/account/findAll";
    }

}
